/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.snda.dw.lidejia.nbbtrace.btrace;

import com.sun.btrace.annotations.ProbeMethodName;
import com.sun.btrace.annotations.ProbeClassName;
import com.sun.btrace.annotations.TargetMethodOrField;
import com.sun.btrace.annotations.TargetInstance;
import com.snda.dw.lidejia.nbbtrace.HelloWorld;
import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.Kind;
import com.sun.btrace.annotations.Location;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.Return;
import com.sun.btrace.annotations.Self;

import static com.sun.btrace.BTraceUtils.*;

/**
 *
 * @author lidejia
 */
@BTrace
public class HelloWorldTrace {

    @OnMethod(clazz = "com.snda.dw.lidejia.nbbtrace.HelloWorld",
    method = "say",
    location =
    @Location(Kind.RETURN))
    public static void onReturn(@Self HelloWorld self,
            String message, @Return String result) {
        println(strcat("Called:", str(self)));
        println(strcat("Message is:", message));
        println(strcat("Return value is:", result));
    }

    @OnMethod(clazz = "com.snda.dw.lidejia.nbbtrace.HelloWorld",
    method = "/.*/",
    location =
    @Location(value = Kind.LINE, line = -1))
    public static void online(@ProbeClassName String pcn, @ProbeMethodName String pmn, int line) {
        print(strcat(pcn, "."));
        print(strcat(pmn, ":"));
        println(line);
    }

    @OnMethod(clazz = "com.snda.dw.lidejia.nbbtrace.HelloWorld",
    method = "say",
    location =
    @Location(value = Kind.CALL, clazz = "com.snda.dw.lidejia.nbbtrace.Love", method = "/.*/"))
    public static void onCall(@TargetInstance Object target, @TargetMethodOrField String targetMethodOrField) {
        println(strcat("Target isntance is:", str(target)));
        println(strcat("Target method or field is:", targetMethodOrField));
    }
}
